package com.taoz.rpc.core.config;

import com.taoz.rpc.core.fault.retry.RetryHelperConstant;
import com.taoz.rpc.core.loadbalancer.LoadBalancerConstant;
import com.taoz.rpc.core.registry.RegistryConstant;
import com.taoz.rpc.core.serializer.SerializerConstant;
import lombok.Data;

@Data
public class ApplicationConfig {
    private static volatile ApplicationConfig config;

    private String name = "taoz-rpc";  // 项目名
    private String version = "1.0";
    private String serverHost = "127.0.0.1";  // 未引入注册中心时，客户端默认访问的host:port
    private int serverPort = 8080;  // 服务端启动端口
    private String serializer = SerializerConstant.DEFAULT_SERIALIZER;

    // 引入注册中心后的配置
    private String registryAddress = "http://localhost:2379";
    private String registryName = RegistryConstant.ETCD_REGISTRY;
    private boolean isServer = true;

    // 负载均衡配置
    private String loadBalancer = LoadBalancerConstant.RANDOM;
    private String retryHelper = RetryHelperConstant.NO;

    private ApplicationConfig() {};

    public static ApplicationConfig getConfig() {
        if (config == null) {
            synchronized (ApplicationConfig.class) {
                if (config == null) {
                    config = ConfigLoader.loadConfig(ApplicationConfig.class, "rpc");
                }
            }
        }
        return config;
    }
}
